package com.suse.lhw.hms.exersiseserver.service.Impl;

import com.suse.lhw.hms.exersiseserver.dao.EMmToUnitMapper;
import com.suse.lhw.hms.exersiseserver.dao.EMoventmodelMapper;
import com.suse.lhw.hms.exersiseserver.domin.EMmToUnit;
import com.suse.lhw.hms.exersiseserver.domin.EMoventmodel;
import com.suse.lhw.hms.exersiseserver.pojo.out.MovementModelAndUnits;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import com.suse.lhw.hms.exersiseserver.dao.EUnitMapper;
import com.suse.lhw.hms.exersiseserver.domin.EUnit;
import com.suse.lhw.hms.exersiseserver.service.EUnitService;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * @ProjectName: health_manage_system
 * @Package: com.suse.lhw.hms.exersiseserver.service.Impl
 * @ClassName: EUnitServiceImpl
 * @Description: java类作用描述
 * @Author: 李鸿炜
 * @CreateDate: 2020/5/3 13:59
 * @UpdateUser: 更新者
 * @UpdateDate: 2020/5/3 13:59
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
@Service
public class EUnitServiceImpl implements EUnitService {

    @Resource
    private EUnitMapper eUnitMapper;
    @Resource
    private EMmToUnitMapper eMmToUnitMapperl;
    @Resource
    private EMoventmodelMapper eMoventmodelMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return eUnitMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(EUnit record) {
        return eUnitMapper.insert(record);
    }

    @Override
    public int insertSelective(EUnit record) {
        return eUnitMapper.insertSelective(record);
    }

    @Override
    public EUnit selectByPrimaryKey(Integer id) {
        return eUnitMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(EUnit record) {
        return eUnitMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(EUnit record) {
        return eUnitMapper.updateByPrimaryKey(record);
    }

    @Override
    public int insertByModelId(int modelId, EUnit eUnit) {
        //增加一个单位
        if (eUnitMapper.insertSelective(eUnit) == 0)
            return 0;
        //增加单位映射
        EMmToUnit eMmToUnit = new EMmToUnit(modelId, eUnit.getId());
        if (eMmToUnitMapperl.insertSelective(eMmToUnit) == 0)
            return 0;
        return 1;
    }

    @Override
    public MovementModelAndUnits selectByModelId(int id) {
        List<EUnit> units = eUnitMapper.selectByMMID(id);
        EMoventmodel eMoventmodel = eMoventmodelMapper.selectByPrimaryKey(id);
        MovementModelAndUnits movementModelAndUnits = new MovementModelAndUnits(
                eMoventmodel.getMmName(), eMoventmodel.getMmImgurl(), eMoventmodel.getMmCategoryId(), eMoventmodel.getStatus(),
                eMoventmodel.getMmPackagetype(), eMoventmodel.getMmDescription(), eMoventmodel.getUserid(), eMoventmodel.getDifficulty(),
                eMoventmodel.getVideourl(), eMoventmodel.getPoints(), units
        );
        return movementModelAndUnits;

    }

}

